home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / pyshared / parted / filesystem.py < prev    next >
Encoding:
Python Source  |  2010-06-29  |  4.6 KB  |  147 lines

  1. #
  2. # filesystem.py
  3. # Python bindings for libparted (built on top of the _ped Python module).
  4. #
  5. # Copyright (C) 2009  Red Hat, Inc.
  6. #
  7. # This copyrighted material is made available to anyone wishing to use,
  8. # modify, copy, or redistribute it subject to the terms and conditions of
  9. # the GNU General Public License v.2, or (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful, but WITHOUT
  11. # ANY WARRANTY expressed or implied, including the implied warranties of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
  13. # Public License for more details.  You should have received a copy of the
  14. # GNU General Public License along with this program; if not, write to the
  15. # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. # 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
  17. # source code or documentation are not subject to the GNU General Public
  18. # License and may only be used or replicated with the express permission of
  19. # Red Hat, Inc.
  20. #
  21. # Red Hat Author(s): David Cantrell <dcantrell@redhat.com>
  22. #
  23.  
  24. import _ped
  25. import parted
  26.  
  27. from decorators import localeC
  28.  
  29. # XXX: add docstrings!
  30.  
  31. class FileSystem(object):
  32.     @localeC
  33.     def __init__(self, type=None, geometry=None, checked=False, PedFileSystem=None):
  34.         if checked:
  35.             c = 1
  36.         else:
  37.             c = 0
  38.  
  39.         if PedFileSystem is None:
  40.             if type is None:
  41.                 raise parted.FileSystemException, "no type specified"
  42.             elif geometry is None:
  43.                 raise parted.FileSystemException, "no geometry specified"
  44.  
  45.             self._type = type
  46.             self._geometry = geometry
  47.             self._checked = checked
  48.             self.__fileSystem = _ped.FileSystem(type=fileSystemType[type], geom=geometry.getPedGeometry(), checked=c)
  49.         else:
  50.             self.__fileSystem = PedFileSystem
  51.             self._type = self.__fileSystem.type.name
  52.             self._geometry = parted.Geometry(PedGeometry=self.__fileSystem.geom)
  53.  
  54.             if self.__fileSystem.checked:
  55.                 self._checked = True
  56.             else:
  57.                 self._checked = False
  58.  
  59.     def __eq__(self, other):
  60.         return not self.__ne__(other)
  61.  
  62.     def __ne__(self, other):
  63.         if hash(self) == hash(other):
  64.             return False
  65.  
  66.         if type(self) != type(other):
  67.             return True
  68.  
  69.         return self.type != other.type or self.geometry != other.geometry
  70.  
  71.     def __str__(self):
  72.         s = ("parted.FileSystem instance --\n"
  73.              "  type: %(type)s  geometry: %(geometry)r  checked: %(checked)s\n"
  74.              "  PedFileSystem: %(ped)r" %
  75.              {"type": self.type, "geometry": self.geometry,
  76.               "checked": self.checked, "ped": self.__fileSystem})
  77.         return s
  78.  
  79.     @property
  80.     def type(self):
  81.         """The type of this filesystem, e.g. ext3."""
  82.         return self._type
  83.  
  84.     @property
  85.     def geometry(self):
  86.         """The Geometry object describing this filesystem."""
  87.         return self._geometry
  88.  
  89.     @property
  90.     def checked(self):
  91.         """True if this filesystem has been checked, False otherwise."""
  92.         return bool(self._checked)
  93.  
  94.     @localeC
  95.     def clobber(self):
  96.         return self.__fileSystem.clobber()
  97.  
  98.     @localeC
  99.     def open(self):
  100.         return parted.FileSystem(PedFileSystem=self.__fileSystem.open())
  101.  
  102.     # XXX: this can take in a Timer
  103.     @localeC
  104.     def create(self):
  105.         return parted.FileSystem(PedFileSystem=self.__fileSystem.create())
  106.  
  107.     @localeC
  108.     def close(self):
  109.         return self.__fileSystem.close()
  110.  
  111.     # XXX: this can take in a Timer
  112.     @localeC
  113.     def check(self):
  114.         return self.__fileSystem.check()
  115.         self._checked = self.__fileSystem.checked
  116.  
  117.     # XXX: this can take in a Timer
  118.     @localeC
  119.     def copy(self, geometry):
  120.         return parted.FileSystem(PedFileSystem=self.__fileSystem.copy(geometry.getPedGeometry()))
  121.  
  122.     # XXX: this can take in a Timer
  123.     @localeC
  124.     def resize(self, geometry):
  125.         return self.__fileSystem.resize(geometry.getPedGeometry())
  126.  
  127.     @localeC
  128.     def getResizeConstraint(self):
  129.         return parted.Constraint(PedConstraint=self.__fileSystem.get_resize_constraint())
  130.  
  131.     def getPedFileSystem(self):
  132.         """Return the _ped.FileSystem object contained in this FileSystem.
  133.            For internal module use only."""
  134.         return self.__fileSystem
  135.  
  136. # collect all filesystem types and store them in a hash
  137. fileSystemType = {}
  138. __type = _ped.file_system_type_get_next()
  139. fileSystemType[__type.name] = __type
  140.  
  141. while True:
  142.     try:
  143.         __type = _ped.file_system_type_get_next(__type)
  144.         fileSystemType[__type.name] = __type
  145.     except:
  146.         break
  147.